// @flow
// import $ from 'jquery'
import React, { Component } from 'react'
import styles from './Bode.css'
import { message, Spin, Row, Col, Button, Radio, Select, Checkbox } from 'antd'
import Highcharts from 'highcharts-release'
import universalFetch, { handleFetchError } from 'store/modules/fetch'
// import bodeData from './bode.json'
const RadioGroup = Radio.Group
const CheckboxGroup = Checkbox.Group
const Option = Select.Option
import moment from 'moment'
type Props = {
  deviceData: Object,
  historyCond: Object,
  channel_id: number, // 历史数据会传值，直接bode数据不传值
  requestType: string // 如果值是wx就是小程序访问的，接口变成域名
}

type States = {
  chartData: Array<any>,
  finalData: Array<Object>, // 画图前得到的数据(KMX请求的数据结果)
  xData: Array<any>,
  susbData: Array<any>,
  channelData: Array<Object>,
  visible: boolean,
  loading: boolean,
  chartVisible: boolean,
  btnValue: string,
  bodeData: Array<Object>, // 伯德接口请求数据时请求的数据
  startTime: any,
  endTime: any,
  bodeChannelIds: Array<any> // bode数据选择的通道数组
}
class Bode extends Component {
  props: Props
  state: States
  getDynamicData: Function
  getSusb: Function
  getBodeData: Function
  drawOne: Function
  drawTwo: Function
  changeBtn: Function
  refreDraw: Function
  timeChange: Function
  kmxDraw: Function
  getBodeChannelIds: Function
  getChannel: Function
  constructor (props: Object) {
    super(props)
    this.state = {
      xData: [],
      finalData: [],
      susbData: [],
      channelData: [],
      visible: true,
      chartData: [],
      loading: false,
      chartVisible: true,
      btnValue: '1',
      bodeData: [],
      startTime: '',
      endTime: '',
      bodeChannelIds: []
    }
    this.getDynamicData = this.getDynamicData.bind(this)
    this.getSusb = this.getSusb.bind(this)
    this.getBodeData = this.getBodeData.bind(this)
    this.drawOne = this.drawOne.bind(this)
    this.drawTwo = this.drawTwo.bind(this)
    this.changeBtn = this.changeBtn.bind(this)
    this.refreDraw = this.refreDraw.bind(this)
    this.timeChange = this.timeChange.bind(this)
    this.kmxDraw = this.kmxDraw.bind(this)
    this.getBodeChannelIds = this.getBodeChannelIds.bind(this)
    this.getChannel = this.getChannel.bind(this)
  }
  componentWillMount () {
    this.getChannel() // 通道数据
    this.getSusb()// 启停机数据
    if (this.props.channel_id) {
      this.setState({
        bodeChannelIds: [this.props.channel_id]
      })
    }
  }

  componentDidMount () {
    this.drawOne()// 空的数据（先执行一下）
  }

  getChannel () {
    // 通道
    const { deviceData, requestType } = this.props
    const id = deviceData.id
    let url = `${__SERVICE_API__}device/devices/${id}/channel-ids`
    if (requestType === 'wx') {
      url = `${__WXSERVICE_API__}device/devices/${id}/channel-ids`
    }
    universalFetch(url)
      .then((res) => res.json())
      .then((json) => {
        if (json.code !== 200000) {
          throw new Error(JSON.stringify({ code: json.code, message: json.message }))
        }
        const channel = json.result.filter((dd) => dd.sensorType === '振动量')
        if (channel.length > 0) {
          this.setState({
            channelData: channel[0].channelIds
          })
        }
      })
      .catch((error) => {
        handleFetchError(error)
        console.error(error)
      })
  }

  getSusb () {
    // 获取设备的启停机(测试数据是${deviceNo[0]}=4， 查询的时间范围改为定值)
    const { deviceData, requestType } = this.props
    const deviceNo = deviceData.id
    let url = `${__SERVICE_API__}device/devices/${deviceNo}/susb?order=desc`
    if (requestType === 'wx') {
      url = `${__WXSERVICE_API__}device/devices/${deviceNo}/susb?order=desc`
    }
    universalFetch(url)
    .then((res) => res.json())
    .then((json) => {
      this.setState({
        susbData: json.result
      })
    })
    .catch((error) => {
      console.error(error)
      handleFetchError(error)
    })
  }

  // 伯德图选择的通道数组
  getBodeChannelIds (values) {
    this.setState({
      bodeChannelIds: values
    })
  }

  getBodeData () {
    const { bodeData } = this.state
    const { requestType } = this.props
    const component = this
    let url = `${__SPE_API__}api/bode`
    if (requestType === 'wx') {
      url = `${__WXSPE_API__}api/bode`
    }
    fetch(url, {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(JSON.stringify(bodeData))
    })
    .then(res => res.json())
    .then((json) => {
      this.setState({
        finalData: json
      }, () => {
        component.drawOne()
      })
    })
    .catch((error) => {
      console.error(error)
      this.setState({
        loading: false,
        finalData: []
      }, () => {
        component.drawOne()
      })
    })
  }

  drawOne () {
    this.setState({
      chartVisible : true,
      loading: false
    })
    const { finalData, channelData } = this.state
    const container = this.refs.chartOne
    const bodeCharts = [
      {
        chart: container,
        title: '通频值',
        xtext: '转速(rmp)',
        ytext: '幅值(μm)',
        chartData: finalData.map((dd, ii) => {
          const channel = channelData.filter((d) => Number(d.id) === Number(dd.id))
          return {
            name: channel[0].name,
            type: 'line',
            // data: dd.spe ? dd.spe.map((d, i) => {
            //   return [d, dd.peak2value[i]]
            // }).sort() : [],
            data: dd.spe ? dd.spe.map((d, i) => {
              return [d, dd.peak2value[i]]
            }) : []
          }
        })
      }
    ]
    this.draw(bodeCharts)
  }

  drawTwo () {
    this.setState({
      chartVisible : false
    })
    const { finalData, channelData } = this.state
    const container = this.refs.chart
    const container2 = this.refs.chart2
    const bodeCharts = [
      {
        chart: container,
        title: '幅值图',
        xtext: '转速(rmp)',
        ytext: '幅值(μm)',
        chartData: finalData.map((dd, ii) => {
          const channel = channelData.filter((d) => Number(d.id) === Number(dd.id))
          return {
            name: channel[0].name,
            type: 'line',
            // data: dd.spe ? dd.spe.map((d, i) => {
            //   return [d, dd.amp_1X[i]]
            // }).sort() : [],
            data: dd.spe ? dd.spe.map((d, i) => {
              return [d, dd.amp_1X[i]]
            }) : []
          }
        })
      },
      {
        chart: container2,
        title: '相位图',
        xtext: '转速(rmp)',
        ytext: '相位(°)',
        chartData: finalData.map((dd, ii) => {
          const channel = channelData.filter((d) => Number(d.id) === Number(dd.id))
          return {
            name: channel[0].name,
            type: 'line',
            // data: dd.spe ? dd.spe.map((d, i) => {
            //   return [d, dd.pha_1X[i]]
            // }).sort() : [],
            data: dd.spe ? dd.spe.map((d, i) => {
              let data = dd.pha_1X[i]
              if (data < 0) {
                data = data + 360
              }
              return [d, data]
            }) : []
          }
        })
      }
    ]
    this.draw(bodeCharts)
  }
  getDynamicData () {
    this.setState({
      loading: true
    })
    const { startTime, endTime, bodeChannelIds, channelData } = this.state
    const { deviceData, requestType } = this.props
    const deviceNo = deviceData.deviceNo.split('_')
    if (bodeChannelIds.length === 0) {
      this.setState({
        loading: false
      })
      message.info('请选择通道')
      return
    }
    const postBody = JSON.stringify({
      // fieldGroup: fieldGroup[0].En,
      fieldGroup: 'c_vib',
      fields: ['speed', 'dyna_value'],
      // fields: ['speed', 'dyna_value', 'average', 'direc'],
      coValueFilter: {
        idFieldFilter: {
          factory_id: { '$eq': String(deviceNo[0]) },
          equipment_id: { '$eq': String(deviceNo[1]) },
          machine_id: { '$eq': String(deviceNo[2]) },
          datatype: { '$eq': '13' },
          '$or': bodeChannelIds.map((d, i) => {
            return { 'channel_id': { '$eq': String(d) } }
          })
        }
      },
      timeRange: {
        // 测试的定时间段
        // start: '2016-07-30T02:46:22.450+08:00',
        // end: '2016-07-30T02:55:40.707+08:00'
        // 按 +8:00格式取数
        start: moment(startTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
        end: moment(endTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ')
        // 不做任何格式变化取数（"2016-07-30T02:57:48.000Z"）
        // start: startTime,
        // end: endTime
        // 强制减8小时，这种情况跟页面数据对应不上，为配合后台启停表与数据表差8h问题
        // start: moment(startTime).subtract(8, 'h').format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
        // end: moment(endTime).subtract(8, 'h').format('YYYY-MM-DDTHH:mm:ss.SSSZ')
      },
      size: 10000,
      page: 1
    })

    let url = `${__KMX_API__}data-streams`
    if (requestType === 'wx') {
      url = `${__WXKMX_API__}data-streams`
    }
    fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: postBody
    })
    .then((res) => res.json())
    .then((json) => {
      if (json.code !== 0) {
        throw new Error(JSON.stringify({ code: json.code, message: json.message }))
      }
      const results = json.results
          // if (results && results[0].streams.length > 0) {
      if (results) {
        const len = results.length / 2 // 计算出结果一共多少组数据
        let Arr = []
        for (let i = 0; i < len; i++) {
          const index = i * 2 // 因为两个个是一组
          const id = results[0 + index].compoundId.channel_id // 存下返回的channel_id（区分名字）
          const speed = results[0 + index].streams.map((d, i) => {
            return Math.round(d[1] / 1000) // 从数据库中取出的转速太大，前端除以1000
          })
          const dynaValue = results[1 + index].streams
          const ArrayTwo = speed.map((d, i) => {
            return [d, dynaValue[i][1].split(',')]
          })
          const channel = channelData.filter((dd) => Number(dd.id) === Number(id))
          Arr.push({
            id: id,
            samples: channel[0].samples,
            speed: ArrayTwo.map((d) => {
              return d[0]
            }),
            value: ArrayTwo.map((d, i) => {
              return d[1]
            })
          })
        }

        this.setState({
          bodeData: Arr
        }, () => {
          this.getBodeData()
        })
        // 底下是处理speed不重复的测试
        // Array.prototype.unique3 = function () {
        //   var res = []
        //   var json = {}
        //   for (var i = 0; i < this.length; i++) {
        //     if (!json[this[i]]) {
        //       res.push(this[i])
        //       json[this[i]] = 1
        //     }
        //   }
        //   return res
        // }
        // const setSpeed = speed.unique3().sort()
        // const allregs = setSpeed.map((d, i) => {
        //   let array = []
        //   ArrayTwo.filter((dd) => Number(dd[0]) === Number(d)).map((dd, ii) => {
        //     dd[1].map((ddd, iii) => {
        //       if (ddd) {
        //         array.push(Number(ddd))
        //       }
        //     })
        //   })
        //   return [d, array]
        // })
        // console.log(allregs);
        // row col 是其中的一种版本，被替代
        // const row = dynaValue.length
        // const col = dynaValue[0][1].split(',').length
        // this.setState({
          // bodeData: {
          //   row: row,
          //   col: col,
          //   speed: ArrayTwo.map((d) => {
          //     return d[0]
          //   }),
          //   value: ArrayTwo.map((d, i) => {
          //     return d[1]
          //   })
          // }
          // 底下是 被处理speed传的方法（去重过[以后不做处理，将元数据传给西交大]）
          // bodeData: {
          //   speed: allregs.map((d) => {
          //     return d[0]
          //   }),
          //   value: allregs.map((d, i) => {
          //     return d[1]
          //   })
          // }
        // }, () => {
        //   this.getBodeData()
        // })
      } else {
        message.info('暂无数据')
        this.setState({
          loading: false,
          finalData: []
        }, () => {
          this.drawOne()
        })
      }
    })
    .catch((error) => {
      console.error(error)
      this.setState({
        loading: false,
        finalData: []
      }, () => {
        this.drawOne()
      })
    })
  }
  draw (bodeCharts: Array<Object>) {
    /**
     * 为了让多个图表的提示框即十字准星线能够联动，这里绑定多个图表的附件 dom 的鼠标事件进行联动
     * (Highcharts.charts.length - 2) 仅循环最后两个
     */
   //  $('#container1').bind('mousemove touchmove touchstart', function (e) {
   //    var chart,
   //      point,
   //      i,
   //      event
   //    for (i = 0; i < Highcharts.charts.length; i = i + 1) {
   //      chart = Highcharts.charts[i]
   //      if (chart && chart.renderTo.title === '伯德图') {
   //        event = chart.pointer.normalize(e.originalEvent)
   //        var pointArr = []
   //        for (var ii = 0; ii < chart.series.length; ii = ii + 1) {
   //          point = chart.series[ii].searchPoint(event, true) // Get the hovered point
   //          pointArr.push(chart.series[ii].searchPoint(event, true)) // Get the hovered point
   //          if (point) {
   //            point.highlight(e, pointArr)
   //          }
   //        }
   //      }
   //    }
   //  })
   // /**
   //  * 重写内部的方法， 这里是将提示框即十字准星的隐藏函数关闭
   //  */
   //
   //  Highcharts.Pointer.prototype.reset = function () {
   //    return undefined
   //  }
   // /**
   //  * 高亮当前的数据点，并设置鼠标滑动状态及绘制十字准星线
   //  */
   //  Highcharts.Point.prototype.highlight = function (event, chart) {
   //    this.onMouseOver() // 显示鼠标激活标识
   //    this.series.chart.xAxis[0].drawCrosshair(event, this) // 显示十字准星线
   //    // this.series.chart.tooltip.refresh([this]) // 显示提示框
   //    this.series.chart.tooltip.refresh(chart) // 显示提示框
   //  }
   /**
    * 同步缩放效果，即当一个图表进行了缩放效果，其他图表也进行缩放
    */
    function syncExtremes (e) {
      var thisChart = this.chart
      if (e.trigger !== 'syncExtremes') {
        Highcharts.each(Highcharts.charts, function (chart) {
          if (chart && chart !== thisChart) {
            if (chart.xAxis && chart.xAxis[0].setExtremes) {
              chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, { trigger: 'syncExtremes' })
            }
          }
        })
      }
    }

    Highcharts.setOptions({ global: { useUTC: false } })
    bodeCharts.map((d, i) => {
      // y轴的最小值（如果都是正数，最小值为0，有负数就不设置最小值）
      let minValue = 0
      d.chartData.map((d, i) => {
        d.data.map((dd, ii) => {
          if (dd[1] < 0) {
            minValue = null
          }
        })
      })
      // 相位图y轴的最大值为360，其他图最大值不限定(用刻度间隔配合实现)
      let tickInterval = null
      let maxValue = null
      if (d.title === '相位图') {
        tickInterval = 180
        maxValue = 360
      }
      let margin = [40, 140, 30, 60]
      if (d.title === '通频值') {
        margin = [40, 20, 30, 60]
      }
      const chart = d.chart
      const innerChart = Highcharts.chart(chart, {
        chart: {
          backgroundColor: 'transparent',
          zoomType: 'x',
          margin: margin
        },
        colors: ['#4572A7', '#89A54E', '#80699B', '#3D96AE', '#AA4643',
          '#DB843D', '#92A8CD', '#A47D7C', '#B5CA92', '#2f7ed8', '#8bbc21', '#910000', '#1aadce',
          '#492970', '#f28f43', '#77a1e5', '#c42525', '#a6c96a', '#0d233a'],
        title: {
          text: d.title,
          style: {
            fontSize: 12
          }
        },
        credits:{
          enabled: false
        },
        legend: {
          enabled: false,
          layout: 'vertical',
          align: 'right',
          verticalAlign: 'bottom'
        },
        tooltip: {
          // positioner: function () {
          //   return {
          //     x: this.chart.chartWidth - this.label.width, // right aligned
          //     y: 30 // align to title
          //   }
          // },
          // borderWidth: 0,
          // backgroundColor: 'none',
          // headerFormat: '',
          // shadow: false,
          shared: true,
          useHTML: true,
          formatter: function () {
            let t = '<p style="text-align: left"><b>' + this.x + '</b></p>'
            this.points.map(function (d, i) {
              const y = d.y.toFixed(3) * 1000 / 1000
              t += '<p style="text-align: left"><span style="color: ' + d.color + '">●</span><b>' + d.series.name + '：' + y + '</b></p>'
            })
            return t
          },
          valueDecimals: 3
        },
        xAxis: {
          crosshair: true,
          title: {
            text: d.xtext,
            align: 'high'
          },
          events: {
            setExtremes: syncExtremes
          }
        },
        yAxis: {
          endOnTick: true,
          tickInterval: tickInterval,
          max: maxValue,
          min: minValue,
          lineWidth: 1,
          tickWidth: 1,
          title: {
            align: 'high',
            offset: 0,
            text: d.ytext,
            rotation: 0,
            y: -15
          }
        },
        plotOptions: {
          line: {
            lineWidth: 1,
            dataGrouping: {
              enabled: false
            }
          },
          series: {
            animation: true,
            allowPointSelect: true,
            cursor: 'pointer',
            point: {
              events: {
                select: function () {
                  // const chart = this.series.chart
                  Highcharts.charts.map((d, i) => {
                    if (d && d.renderTo.title === '伯德图') {
                      const x = this.category
                      let yText = ''
                      d.series.map((dd, ii) => {
                        const yData = d.series[ii].data.filter((dd) => dd.category === x)
                        if (yData.length === 0) return
                        const y = yData[0].y
                        yText += '<span style="color:' + d.series[ii].color + ';margin-right:5px">●</span>' +
                        d.series[ii].name + ':' + y.toFixed(3) * 1000 / 1000 + '<br/>'
                      })
                      const text = x.toFixed(3) * 1000 / 1000 + '<br/> ' + yText
                      d.xAxis[0].removePlotLine('plot-line-1')
                      d.xAxis[0].addPlotLine({
                        value: this.category,
                        color: '#000',
                        width: 0.5,
                        id: 'plot-line-1'
                      })
                      if (!d.lbl) {
                        d.lbl = d.renderer.label(text, d.chartWidth - d.marginRight, 40)
                          .attr({
                            padding: 5,
                            r: 5,
                            fill: '#fff',
                            zIndex: 5
                          })
                        .css({
                          color: '#000'
                        })
                          .add()
                      } else {
                        d.lbl.attr({
                          text: text
                        })
                      }
                    }
                  })
                }
              }
            }
          }
        },
        series: d.chartData
      })
      setTimeout(() => {
        innerChart.reflow()
      }, 5)
    })
  }

  changeBtn (e: Object) {
    const value = e.target.value
    this.setState({
      btnValue: value
    })
    if (value === '1') {
      this.drawOne()
    } else {
      this.drawTwo()
    }
  }

  refreDraw () {
    this.setState({
      btnValue: '1'
    })
    this.getDynamicData()
  }

  kmxDraw () {
    this.setState({
      btnValue: '1'
    })
    // 从Kmx中直接取出bode结果
    this.setState({
      loading: true
    })
    const { startTime, endTime, bodeChannelIds, channelData } = this.state
    const { deviceData, requestType } = this.props
    const deviceNo = deviceData.deviceNo.split('_')
    if (bodeChannelIds.length === 0) {
      this.setState({
        loading: false
      })
      message.info('请选择通道')
      return
    }
    const postBody = JSON.stringify({
      // fieldGroup: fieldGroup[0].En,
      fieldGroup: 'c_vib',
      fields: ['speed', 'direc', 'v1x', 'p1x'],
      // fields: ['speed', 'dyna_value', 'average', 'direc'],
      // sampleTime: this.props.checkTime,
      coValueFilter: {
        idFieldFilter: {
          factory_id: { '$eq': String(deviceNo[0]) },
          equipment_id: { '$eq': String(deviceNo[1]) },
          machine_id: { '$eq': String(deviceNo[2]) },
          datatype: { '$eq': '13' },
          '$or': bodeChannelIds.map((d, i) => {
            return { 'channel_id': { '$eq': String(d) } }
          })
        }
      },
      timeRange: {
        // 测试的定时间段
        // start: '2016-07-30T02:46:22.450+08:00',
        // end: '2016-07-30T02:55:40.707+08:00'
        // 按 +8:00格式取数
        start: moment(startTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
        end: moment(endTime).format('YYYY-MM-DDTHH:mm:ss.SSSZ')
        // 不做任何格式变化取数（"2016-07-30T02:57:48.000Z"）
        // start: startTime,
        // end: endTime
        // 强制减8小时，这种情况跟页面数据对应不上，为配合后台启停表与数据表插8h问题
        // start: moment(startTime).subtract(8, 'h').format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
        // end: moment(endTime).subtract(8, 'h').format('YYYY-MM-DDTHH:mm:ss.SSSZ')
      },
      size: 10000,
      page: 1
    })
    let url = `${__KMX_API__}data-streams`
    if (requestType === 'wx') {
      url = `${__WXKMX_API__}data-streams`
    }
    fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: postBody
    })
    .then((res) => res.json())
    .then((json) => {
      if (json.code !== 0) {
        throw new Error(JSON.stringify({ code: json.code, message: json.message }))
      }
      const results = json.results
      if (results) {
        const len = results.length / 4 // 计算出结果一共多少组数据
        let Arr = []
        for (let i = 0; i < len; i++) {
          const index = i * 4 // 因为四个是一组
          const id = results[0 + index].compoundId.channel_id // 存下返回的channel_id（区分名字）
          Arr.push({
            id: id,
            spe: results[0 + index].streams.map((d, i) => {
              return Math.round(d[1] / 1000) // 从数据库中取出的转速太大，前端除以1000
            }),
            peak2value: results[1 + index].streams.map((d, i) => {
              return d[1]
            }),
            amp_1X: results[2 + index].streams.map((d, i) => {
              return d[1]
            }),
            pha_1X: results[3 + index].streams.map((d, i) => {
              let data = d[1]
              if (data < 0) {
                data = data + 360
              }
              return data
            })
          })
        }
        this.setState({
          finalData: Arr
        }, () => {
          this.drawOne()
        })
      } else {
        message.info('暂无数据')
        this.setState({
          loading: false,
          finalData: []
        }, () => {
          this.drawOne()
        })
      }
    })
    .catch((error) => {
      console.error(error)
      this.setState({
        loading: false,
        finalData: []
      }, () => {
        this.drawOne()
      })
    })
  }

  timeChange (e) {
    const { value } = e.target
    this.setState({
      startTime: value.startTime,
      endTime: value.stopTime
    })
  }

  render () {
    const { loading, susbData, chartVisible, btnValue, channelData, bodeChannelIds } = this.state
    let plainOptions = []
    if (susbData.length > 0) {
      plainOptions = susbData.map((d) => {
        const type = d.type
        let typeStr
        if (type === 0) {
          typeStr = '启'
        } else if (type === 1) {
          typeStr = '停'
        } else if (type === 2) {
          // typeStr = '停止进入停止'
          typeStr = ''
        } else if (type === 3) {
          // typeStr = '正常进入正常'
          typeStr = ''
        } else if (type === 9) {
          // typeStr = '正在启停机'
          typeStr = ''
        }
        const start = moment(d.startTime).format('YYYY-MM-DD HH:mm:ss')
        const end = moment(d.stopTime).format('YYYY-MM-DD HH:mm:ss')
        return { label: typeStr, time:start + '~' + end, value: d }
      })
    }
    const radioStyle = {
      display: 'block',
      paddingLeft: '10px'
    }
    return (
      <div className={styles['main']}>
        <Row className={styles['mainCon']}>
          <Col span={7} style={{ width: 300 }}>
            通道与启停机时间：
            {
              // <Select
              //   multiple
              //   placeholder='请选择通道'
              //   defaultValue={bodeChannelIds}
              //   filterOption={(input, option) => {
              //     return option.props.children.indexOf(input) >= 0
              //   }}
              //   onChange={this.getBodeChannelIds}
              //   style={{ width: '100%', marginTop: 10 }}
              // >
              //   {
              //    channelData.map((d, i) => {
              //      return <Option key={String(d.id)} value={String(d.id)}>{d.name}</Option>
              //    })
              //  }
              // </Select>
            }
            <div className={styles['leftCon']}>
              <div className={styles['leftConL']}>
                <CheckboxGroup options={
                  channelData.map((d, i) => {
                    return { label: d.name, value: String(d.id) }
                  })
                } defaultValue={bodeChannelIds} onChange={this.getBodeChannelIds} />
              </div>
              <div className={styles['leftConR']}>
                <RadioGroup onChange={this.timeChange}>
                  {
                    plainOptions.map((d, i) => {
                      return <Radio style={radioStyle} key={i} value={d.value}>
                        {d.label}<br /><span style={{ marginLeft: 22 }}>{d.time}</span>
                      </Radio>
                    })
                  }
                </RadioGroup>
              </div>
            </div>
            <p className={styles['leftFooter']}>
              <Button type='primary' onClick={this.refreDraw} disabled={loading}>绘制</Button>
              <Button style={{ marginLeft: '10px' }} onClick={this.kmxDraw} disabled={loading}>KMX取值</Button>
            </p>
          </Col>
          <Col span={17} style={{ width: 'calc(100% - 300px)' }}>
            <p className={styles['bodeBtn']}>
              <Radio.Group onChange={this.changeBtn} value={btnValue}>
                <Radio.Button value='1'>通频值</Radio.Button>
                <Radio.Button value='2'>一倍频</Radio.Button>
              </Radio.Group>
            </p>
            <div style={{ display: chartVisible ? 'block' : 'none' }}>
              <Spin spinning={loading} tip='加载中...'>
                <div ref='chartOne' className={styles['chartOne']} />
              </Spin>
            </div>
            <div id='container1' style={{ display: !chartVisible ? 'block' : 'none' }}>
              <Spin spinning={loading} tip='加载中...'>
                <div ref='chart' title='伯德图' className={styles['chart']} />
              </Spin>
              <Spin spinning={loading} tip='加载中...'>
                <div ref='chart2' title='伯德图' className={styles['chart']} />
              </Spin>
            </div>
          </Col>
        </Row>
      </div>
    )
  }
}

export default Bode
